import Vue from "vue";
import Vuex from "vuex";
import _CONST from '../static/utils/const.util'
import ValidatorUtils from '../static/utils/common-util'
Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    token: ""
  },
  mutations: {
    get_token(state) {
      if (ValidatorUtils.isEmpty(state.token)) {
        state.token = ValidatorUtils.isEmpty(localStorage.getItem(_CONST.TOKEN_STORE_KEY)) ? "" : localStorage.getItem(_CONST.TOKEN_STORE_KEY)
      }
    },
    set_token(state, token) {
      if (token) {
        state.token = token
        localStorage.setItem(_CONST.TOKEN_STORE_KEY, token)
      }
    },
    del_token(state) {
      state.token = ''
      localStorage.removeItem(_CONST.TOKEN_STORE_KEY)
    },
  },
  actions: {},
  modules: {}
});
